python sort a list of tuples

38

Sort a list of tuples by an item in Python -

lst = [("val1", 2), ("val1", 1)]
lst.sort()
print(lst)
# Output: [('val1', 1), ('val2', 2)]

Comments

Submit
0 Comments